package com.xl.juc;

import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch 减法计数器
 * @author Charley
 * @create 2020-12-27
 */
public class CountDownLatchTest {

    public static void main(String[] args) throws InterruptedException {
        //倒计时
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <=6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"go ...");
                countDownLatch.countDown();//数量减1
            },String.valueOf(i)).start();
        }
        countDownLatch.await();//等待计数器归零，然后再执行
        System.out.println("close door");
    }
}
